package ChatRoom;

import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

public class SocketMode {
    private Socket socket;
    private String clientName;

    private static List<SocketMode> clientList = new ArrayList<>();

    public SocketMode(Socket socket, String clientName) {
        this.socket = socket;
        this.clientName = clientName;
        clientList.add(this);
    }

    public Socket getSocket() {
        return socket;
    }

    public void setSocket(Socket socket) {
        this.socket = socket;
    }

    public String getClientName() {
        return clientName;
    }

    public void setClientName(String clientName) {
        this.clientName = clientName;
    }

    public static List<SocketMode> getClientList() {
        return clientList;
    }

    // 移除客户端
    public static void removeClient(SocketMode socketMode) {
        clientList.remove(socketMode);
    }

    public boolean equals(Object obj) {
        if (obj == null) return false;
        if (this == obj) return true;
        if (getClass() != obj.getClass()) return false;

        SocketMode other = (SocketMode) obj;
        return this.socket.equals(other.socket);
    }
    public int hashCode() {
        return socket.hashCode();
    }
}
